<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>修改客户</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon"/>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/css/font.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/css/xadmin.css">
    <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/static/lib/layui/layui.js"
            charset="utf-8"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/static/js/xadmin.js"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>

<body>
<div class="x-body">
    <form class="layui-form">
        <input name="id" value="${customer.id}" hidden>
        <div class="layui-form-item">
            <label for="name" class="layui-form-label">
                <span class="x-red">*</span>客户姓名
            </label>
            <div class="layui-input-inline">
                <input value="${customer.name}" type="text" id="name" name="name" lay-verify="required"
                       autocomplete="off" class="layui-input">
            </div>
            <div class="layui-form-mid layui-word-aux">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">
                <span class="x-red">*</span>性别
            </label>
            <div class="layui-input-inline" style="width: 220px">
                <input type="radio" name="gender" value="0" title="男"
                       <c:if test="${customer.gender == 0}">checked</c:if>>
                <input type="radio" name="gender" value="1" title="女"
                       <c:if test="${customer.gender == 1}">checked</c:if>>
                <input type="radio" name="gender" value="2" title="保密"
                       <c:if test="${customer.gender == 2}">checked</c:if>>
            </div>
            <div class="layui-form-mid layui-word-aux">
            </div>
            <label class="layui-form-label">
                <span class="x-red"></span>生日
            </label>
            <div class="layui-input-inline">
                <input value="${customer.birthday}" autocomplete="off" class="layui-input"
                       placeholder="${customer.birthday}" name="birthday" id="birthday">
            </div>
            <div class="layui-form-mid layui-word-aux">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">
                <span class="x-red">*</span>类型
            </label>
            <div class="layui-input-inline">
                <select name="type" lay-verify="required">
                    <option value="0" <c:if test="${customer.type == 0}">selected</c:if>>普通客户</option>
                    <option value="1" <c:if test="${customer.type == 1}">selected</c:if>>大客户</option>
                    <option value="2" <c:if test="${customer.type == 2}">selected</c:if>>VIP客户</option>
                    <option value="3" <c:if test="${customer.type == 3}">selected</c:if>>银卡客户</option>
                    <option value="4" <c:if test="${customer.type == 4}">selected</c:if>>金卡客户</option>
                </select>
            </div>
            <div class="layui-form-mid layui-word-aux">
            </div>
            <label class="layui-form-label">
                <span class="x-red">*</span>状态
            </label>
            <div class="layui-input-inline">
                <select name="status" lay-verify="required">
                    <option value="1" <c:if test="${customer.status == 1}">selected</c:if>>正常</option>
                    <option value="0" <c:if test="${customer.status == 0}">selected</c:if>>禁用</option>
                    <option value="2" <c:if test="${customer.status == 2}">selected</c:if>>已流失</option>
                </select>
            </div>
            <div class="layui-form-mid layui-word-aux">
            </div>
        </div>
        <div class="layui-form-item">
            <label for="tel" class="layui-form-label">
                <span class="x-red">*</span>手机
            </label>
            <div class="layui-input-inline">
                <input value="${customer.tel}" type="text" id="tel" name="tel" lay-verify="required"
                       autocomplete="off" class="layui-input">
            </div>
            <div class="layui-form-mid layui-word-aux">
            </div>

            <label for="officeTel" class="layui-form-label">
                <span class="x-red"></span>办公电话
            </label>
            <div class="layui-input-inline">
                <input value="${customer.officeTel}" type="text" id="officeTel" name="officeTel"
                       autocomplete="off" class="layui-input">
            </div>
            <div class="layui-form-mid layui-word-aux">
            </div>
        </div>
        <div class="layui-form-item">
            <label for="email" class="layui-form-label">
                <span class="x-red"></span>电子邮箱
            </label>
            <div class="layui-input-inline">
                <input value="${customer.email}" type="text" id="email" name="email"
                       autocomplete="off" class="layui-input">
            </div>
            <div class="layui-form-mid layui-word-aux">
            </div>

            <label for="homeTel" class="layui-form-label">
                <span class="x-red"></span>家庭电话
            </label>
            <div class="layui-input-inline">
                <input value="${customer.homeTel}" type="text" id="homeTel" name="homeTel"
                       autocomplete="off" class="layui-input">
            </div>
            <div class="layui-form-mid layui-word-aux">
            </div>
        </div>
        <div class="layui-form-item">
            <label for="addr" class="layui-form-label">
                <span class="x-red"></span>联系地址
            </label>
            <div class="layui-input-inline">
                <textarea style="resize:both;overflow:auto;width: 510px" id="addr" name="addr" placeholder="请输入"
                          class="layui-textarea">${customer.addr}</textarea>
            </div>
            <div class="layui-form-mid layui-word-aux">
            </div>
        </div>
        <div class="layui-form-item">
            <label for="note" class="layui-form-label">
                <span class="x-red"></span>备注信息
            </label>
            <div class="layui-input-inline">
                <textarea style="resize:both;overflow:auto;width: 510px" id="note" name="note" placeholder="请输入"
                          class="layui-textarea">${customer.note}</textarea>
            </div>
            <div class="layui-form-mid layui-word-aux">
            </div>
        </div>
        <div class="layui-form-item">
            <button class="layui-btn" lay-filter="edit" lay-submit="">
                修改
            </button>
        </div>
    </form>
</div>
<script>
    var from;
    layui.use(['laydate', 'form', 'layer'], function () {
        var laydate = layui.laydate;
        //执行一个laydate实例
        laydate.render({
            elem: '#birthday' //指定元素
        });

        $ = layui.jquery;
        form = layui.form;
        var layer = layui.layer;

        //监听提交
        form.on('submit(edit)', function (data) {
            var postData = data.field;
            //发异步，把数据提交给java
            // 提交后台
            $.ajax({
                type: "post",
                url: "${pageContext.request.contextPath}/cm/customer/updateCustomer",
                data: postData,
                dataType: "json",
                success: function (res) {
                    layer.alert(res.msg, {icon: 6}, function () {
                        // 刷新父级的表格
                        parent.table.reload('data');
                        // 获得frame索引
                        var index = parent.layer.getFrameIndex(window.name);
                        //关闭当前frame
                        parent.layer.close(index);
                    });
                }
            });
            return false;
        });
    });

</script>

</body>

</html>